package chapter06.group;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class EmpBean implements WritableComparable<EmpBean> {
    private String empNo;
    private String eName;
    private String job;
    private String mgr;
    private String hireDate;
    private String sal;
    private String comm;
    private String deptNo;

    public EmpBean() {
    }

    public EmpBean(String[] object) {
        empNo = object[0];
        eName = object[1];
        job = object[2];
        mgr = object[3];
        hireDate = object[4];
        sal = object[5];
        comm = object[6];
        deptNo = object[7];
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(empNo);
        dataOutput.writeUTF(eName);
        dataOutput.writeUTF(job);
        dataOutput.writeUTF(mgr);
        dataOutput.writeUTF(hireDate);
        dataOutput.writeUTF(sal);
        dataOutput.writeUTF(comm);
        dataOutput.writeUTF(deptNo);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        empNo = dataInput.readUTF();
        eName = dataInput.readUTF();
        job = dataInput.readUTF();
        mgr = dataInput.readUTF();
        hireDate = dataInput.readUTF();
        sal = dataInput.readUTF();
        comm = dataInput.readUTF();
        deptNo = dataInput.readUTF();
    }

    @Override
    public String toString() {
        return "EmpBean{" +
                "empNo='" + empNo + "\t" +
                ", eName='" + eName + "\t" +
                ", job='" + job + "\t" +
                ", mgr='" + mgr + "\t" +
                ", hireDate='" + hireDate + "\t" +
                ", sal='" + sal + "\t" +
                ", comm='" + comm + "\t" +
                ", deptNo='" + deptNo + "\t" +
                '}';
    }

    @Override
    public int compareTo(EmpBean o) {
        return deptNo.compareTo(o.deptNo);
    }

    public void set(String[] object) {
        empNo = object[0];
        eName = object[1];
        job = object[2];
        mgr = object[3];
        hireDate = object[4];
        sal = object[5];
        comm = object[6];
        deptNo = object[7];
    }

    public String getDeptNo() {
        return deptNo;
    }
}
